<?php

namespace app\admin\controller;

use app\admin\service\MenuService;
use app\admin\service\RoleService;
use support\Request;

class RoleController extends Curd
{


    public function index()
    {
        if (request()->isAjax()) {
            $roleService = new RoleService();
            $res = $roleService->getList(request()->all());
            return sparkSuccess($res);
        }
        return view('role/index');
    }

    /**
     * 添加
     */
    public function add()
    {
        if (request()->isAjaxPost()) {
            $param = request()->post();
            $roleService = new RoleService();
            $res = $roleService->addRole($param);
            return sparkSuccess($res);
        }
        return sparkSuccess(dataReturn(0, 'success', (new MenuService())->getNodeTree()));
    }


    /**
     * 编辑
     */
    public function edit(Request $request)
    {
        if (request()->isAjaxPost()) {
            $param = request()->post();
            $roleService = new RoleService();
            $res = $roleService->editRole($param);
            return sparkSuccess($res);
        }

        return sparkSuccess(dataReturn(0, 'success', (new MenuService())->getNodeTree()));
    }


    /**
     * 删除
     */
    public function del()
    {
        $id = request()->input('id');
        $roleService = new RoleService();
        $res = $roleService->delRole($id);
        return sparkSuccess($res);
    }


}